package dk.itu.mobile.webclient;

import dk.itu.smds.e2012.week04.RestClient;

public class WebClient extends RestClient{

	private String uri = "http://localhost:8080/rest/taskmanager/tasks";
	
	public String getAttendantTasks(String attendantId, int serviceOption) {
		String result = "";
		String requestUri = uri + "?attid=" + attendantId + "&opt=" + serviceOption;	
		
		result = DoRestCall(requestUri, "GET", "");
		
		return result;
	}
	
	public void createTask(String taskXml, int serviceOption) {
		String requestUri = uri + "?opt=" + serviceOption;
		
		DoRestCall(requestUri, "POST", taskXml);
    }
    
	public void deleteTask(String taskId, int serviceOption) {
		String requestUri = uri + "?taskid=" + taskId + "&opt=" + serviceOption;
		
		DoRestCall(requestUri, "DELETE", "");	    	
    }

	
	public static void main(String[] args) {
		WebClient testClient = new WebClient();	
		String testAttendant = "rao";
    	String testAttendant2 = "dianaross";
		String testTaskXML = "<task id='club54' name='The End of Modern-day Gomorrah' date='04-02-1980' status='so-executed'><description>Closing party of Club 54</description><attendants>andywarhole, michaeljackson, dianaross, rao</attendants></task></tasks>";
		String testTaskId = "club54";
		
		//Test getAttendantTasks
		System.out.println("TEST: getAttendantTasks");
		String testGetAttendantService = testClient.getAttendantTasks(testAttendant, 1);
		System.out.println("test GetAttendant on 1 for Rao \n" + testGetAttendantService);
		System.out.println();
		testGetAttendantService = testClient.getAttendantTasks(testAttendant2, 1);
		System.out.println("test GetAttendant on 1 for Diana Ross \n" + testGetAttendantService);
		System.out.println();

		testGetAttendantService = testClient.getAttendantTasks(testAttendant, 2);
		System.out.println("test GetAttendant on 2 for Rao \n" + testGetAttendantService);
		System.out.println();
		testGetAttendantService = testClient.getAttendantTasks(testAttendant2, 2);
		System.out.println("test GetAttendant on 2 for Diana Ross \n" + testGetAttendantService);
		System.out.println();

		testGetAttendantService = testClient.getAttendantTasks(testAttendant, 3);
		System.out.println("test GetAttendant on both for Rao \n" + testGetAttendantService);
		System.out.println();
		testGetAttendantService = testClient.getAttendantTasks(testAttendant2, 3);
		System.out.println("test GetAttendant on both for Diana Ross \n" + testGetAttendantService);
		System.out.println();

		//Test createTask
		System.out.println("TEST: createTask");
		testClient.createTask(testTaskXML, 1);
		testGetAttendantService = testClient.getAttendantTasks(testAttendant2, 1);
		System.out.println("test GetAttendant on 1 for Diana Ross \n" + testGetAttendantService);
		System.out.println();
		
		testClient.createTask(testTaskXML, 2);
		testGetAttendantService = testClient.getAttendantTasks(testAttendant2, 2);
		System.out.println("test GetAttendant on 2 for Diana Ross \n" + testGetAttendantService);
		System.out.println();
		
		//Test deleteTask
		System.out.println("TEST: deleteTask");
		testClient.deleteTask(testTaskId, 1);
		testGetAttendantService = testClient.getAttendantTasks(testAttendant2, 1);
		System.out.println("test deleteTask on 1 for Diana Ross \n" + testGetAttendantService);
		System.out.println();
		
		testClient.deleteTask(testTaskId, 2);
		testGetAttendantService = testClient.getAttendantTasks(testAttendant2, 2);
		System.out.println("test deleteTask on 2 for Diana Ross \n" + testGetAttendantService);
		System.out.println();
		
	}

}
